/**
* @Name: pageItem
* @Desc: 边框组件
*/
<template>
  <div class="pageItemBody">
    <div class="pageItemBodyInner" ref="inner" v-if="show">
      <titleCom :icon="icon" :name="name"></titleCom>
      <!--      主题部分-->
      <div class="itemMain">
        <div class="icon_left_top"></div>
        <div class="icon_right_bottom"></div>
        <div class="mainLine">
          <div class="mainLineInner" ref="mainLineInner"></div>
        </div>
        <slot></slot>
      </div>
    </div>
    <!--    向下展开的背景-->
    <div class="bg" ref="bg" v-if="!show"></div>
  </div>
</template>

<script>

import gsap from 'gsap'
import titleCom from './titleCom.vue'

export default {
  name: "item",
  data() {
    return {
      show: false
    }
  },
  components: {titleCom},
  props: {
    name: {
      type: String,
      default() {
        return '';
      }
    },
    icon: {
      type: String,
      default() {
        return '';
      }
    },
    delay: {
      type: Number,
      default() {
        return 0;
      }
    },
    duration: {
      type: Number,
      default() {
        return 0.5;
      }
    },
  },
  mounted() {
    var that = this;
    gsap.to(this.$refs.bg, {
      height: '100%',
      delay: that.delay,
      duration: that.duration, // 动画持续时间（以秒为单位）
      ease: 'none', // 使用线性动画缓动函数
      onComplete: () => {
        // 动画完成后触发的回调函数
        console.log('动画执行完成');
        setTimeout(() => {
          that.show = true
          // 添加新的 GSAP 动画来改变透明度
          that.$nextTick(() => {
            gsap.to(that.$refs.inner, {
              opacity: 1,
              duration: 1, // 这里可以设置渐显动画的持续时间
            });
            that.startAnimation()
          })
        }, 100)
      },
    });
  },
  methods: {
    startAnimation() {
      gsap.to(this.$refs.mainLineInner, {
        duration: 3,
        right: "120%",
        repeat: -1,
        ease: "linear"
      });
    }
  },
}
</script>

<style lang="scss" scoped>
.pageItemBody {
  width: 100%;
  position: relative;
  height: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: nowrap;
  flex-direction: column;
  z-index: 1;
  align-content: flex-start;

  .titleInfo {
    width: calc(100% - 0px);
    margin: 0 auto;
    height: 60px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: nowrap;
    flex-direction: row;
    align-content: flex-start;
  }
}

.pageItemBodyInner {
  width: 100%;
  position: relative;
  height: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: nowrap;
  flex-direction: column;
  z-index: 1;
  align-content: flex-start;
  opacity: 0;
  //background: url("./assets/itembg.png") center top no-repeat;
  //background-size: 100% 100%;
}

.bg {
  height: 0%;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(to bottom, rgba(#414c67, 0.3), rgba(#414c67, 0.6));
}

.itemMain {
  position: relative;
  width: 100%;
  height: calc(100% - 50px);
  margin-top: 5px;
  z-index: 10;
  border: 1px solid #233b58;
  background: rgba(159, 190, 255, 0.03);
  box-shadow: 14px 27px 73px 0px rgba(6, 9, 17, 0.08);

  .icon_left_top {
    background: url("./assets/icon_left_top.png") no-repeat;
    width: 5px;
    height: 5px;
    background-size: 100% 100%;
    position: absolute;
    left: 0;
    top: 0;
  }

  .icon_right_bottom {
    background: url("./assets/icon_right_bottom.png") no-repeat;
    width: 5px;
    height: 5px;
    background-size: 100% 100%;
    position: absolute;
    right: 0;
    bottom: 0;
  }

  .mainLine {
    height: 1px;
    position: absolute;
    background: rgba(53, 80, 111, 1);
    bottom: 0;
    width: 100%;
    display: flex;
    overflow: hidden;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    flex-direction: row;
    align-content: flex-start;

    .mainLineInner {
      width: 40%;
      position: absolute;
      right: -30%;
      top: 0;
      height: 1px;
      background: linear-gradient(to right, #314472, #5e93d3 50%, #314472);
    }
  }
}
</style>

